/**
 * 获取留言列表
 */
import BaseController from "./common/BaseController"
import { isEmpty } from "../utils/utils"

class GetLeaveListController extends BaseController {
    constructor() {
        super()
        this.mainMethod = this.mainMethod.bind(this)
        this.state = {
            request: null,
            response: null,
            next: null,
        }
    }

    mainMethod (req, res, next) {
        this.state.request = req
        this.state.response = res
        this.state.next = next
        this.handleBusiness()
    }

    async handleBusiness () {
        const { response, request } = this.state
        // let token = request.headers.authorzation

        // //token验证
        // const verifyTokenMiddle = await this.verifyTokenMiddle(token, response)
        // // token验证失败；token过期
        // if (verifyTokenMiddle.status == -2) {
        //     response.json({
        //         code: -2,
        //         msg: verifyTokenMiddle.msg,
        //     })
        //     return
        // }

        let pagingResult = await this.pagingController({
            request,
            response,
            params: [],
            total_sql: "select count(*) as total from wd_leave_message",
            paging_sql:
                "select * from wd_leave_message order by create_time desc limit",
        })
        if (isEmpty(pagingResult)) return

        pagingResult = { data: pagingResult, code: 1, msg: "获取成功" }
        response.json(pagingResult)
    }
}

export default new GetLeaveListController().mainMethod
